#include "misc.h"

int cast(char *toConvert)
{
   for(unsigned int i=0;i<strlen(toConvert);i++)
   {
      if(toConvert[i] < 48 || toConvert[i] > 57)
      {
         return -1;
      }
   }
   return atoi(toConvert);
}

void split(char *buffer, char delimiter, struct multiString *splitBuffer)
{
   int index = 0, begin = 0;
   for(unsigned int i=0; i<=strlen(buffer); i++)
   {
      if(buffer[i] == '\n')
      {
         buffer[i] = '\0';
      }
      if(buffer[i] == delimiter || buffer[i] == '\0')
      {
         for(unsigned int j=begin; j<i; j++)
         {
            splitBuffer->s[index][j-begin] = buffer[j];
            splitBuffer->s[index][j-begin+1] = '\0';
         }
         begin = i+1;
         index++;
         splitBuffer->length++;
      }
   }
}
